package com.cskaoyan.service;

import com.cskaoyan.bean.BO.CommentDeleteBO;
import com.cskaoyan.bean.PO.MarketComment;
import com.cskaoyan.bean.PO.MarketCommentExample;
import com.cskaoyan.bean.PO.MarketGoods;
import com.cskaoyan.bean.VO.MarketCommentVo;
import com.cskaoyan.bean.common.BasePageInfo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.mapper.MarketCommentMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author linhanxin
 * @date 2022/8/15.
 */
@Service
public class AdminCommentServiceImpl implements AdminCommentService {
    @Autowired
    MarketCommentMapper marketCommentMapper;
    public CommonData<MarketCommentVo> queryAll(BasePageInfo info, Integer userId, Integer valueId) {
        PageHelper.startPage(info.getPage(), info.getLimit());
        MarketCommentExample example = new MarketCommentExample();
        String orderByClause = info.getSort() + " " + info.getOrder();
        example.setOrderByClause(orderByClause);
        MarketCommentExample.Criteria criteria = example.createCriteria();
        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (valueId != null) {
            criteria.andValueIdEqualTo(valueId);
        }
        List<MarketComment> commentList = marketCommentMapper.selectByExample(example);
        PageInfo<MarketComment> pageInfo = new PageInfo<>(commentList);
        return CommonData.data(pageInfo);
    }

    @Override
    public void delete(Integer id) {
        MarketCommentExample example = new MarketCommentExample();
        MarketCommentExample.Criteria criteria = example.createCriteria();
        criteria.andIdEqualTo(id);
        marketCommentMapper.deleteByExample(example);
    }
}
